const { wyy_request } = require("../../../util/wyy_request");
const APIError = require("../../../middlewares/rest").APIError;

let playlist = async (ctx) => {

    if (ctx.request.method === 'GET') {
        var before = ctx.request.query.updateTime || '0';
        var limit = ctx.request.query.limit || '20';
        var category = ctx.request.query.categoryId || '全部';
        // console.log(typeof ctx.request.query.limit, limit);
    } else if (ctx.request.method === 'POST') {
        var before = ctx.request.body.updateTime || '0';
        var limit = ctx.request.body.limit || '20';
        var category = ctx.request.body.categoryId || '全部';
    }

    if (before.length === 0) {
        throw new APIError("wyy_playlist", "page not found");
    }

    let result = await wyy_request(`https://music.163.com/api/playlist/highquality/list`, {
        cat: category || '全部', // 全部,华语,欧美,韩语,日语,粤语,小语种,运动,ACG,影视原声,流行,摇滚,后摇,古风,民谣,轻音乐,电子,器乐,说唱,古典,爵士
        limit: limit || 50,
        lasttime: before || 0, // 歌单updateTime
        total: true,
    });

    ctx.rest(result.data);
}

let playlist_Category = async (ctx) => {

    let result = await wyy_request(`https://music.163.com/api/playlist/highquality/tags`);

    ctx.rest(result.data);
}


let playlist_Info = async (ctx) => {
    if (ctx.request.method === 'GET') {
        var pid = ctx.request.query.pid || '';
        // console.log(typeof ctx.request.query.limit, limit);
    } else if (ctx.request.method === 'POST') {
        var pid = ctx.request.body.pid || '';
    }

    if (pid.length === 0) {
        throw new APIError("wyy_playlist", "pid not found");
    }

    let result = await wyy_request(`https://music.163.com/api/v6/playlist/detail`, {
        id: pid,
        n: 100000,
        s: 8,
    });

    ctx.rest(result.data);
}

module.exports = {
    playlist_Info,
    playlist,
    playlist_Category
}